package com.homer.gps.track.helper;

import java.io.IOException;

import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.media.ExifInterface;

public class RecordedImage {

	Bitmap mBitmap;
	String mPath;
	String mMeasuredPath;
	String mName;
	boolean isDimmed;

	public RecordedImage(Bitmap bitmap, String path) {
		mBitmap = bitmap;
		mPath = path;

		if (mBitmap != null) {
			try {
				ExifInterface exif = new ExifInterface(path);
				int o = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
				if (o != ExifInterface.ORIENTATION_NORMAL) {
					Matrix m = new Matrix();
					switch (o) {
					case ExifInterface.ORIENTATION_ROTATE_90:
						m.postRotate(90);
						break;
					case ExifInterface.ORIENTATION_ROTATE_180:
						m.postRotate(180);
						break;
					case ExifInterface.ORIENTATION_ROTATE_270:
						m.postRotate(270);
						break;
					}
					mBitmap = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), m, true);
				}
			} catch (IOException e) {
			}
		}
	}

	public Bitmap getBitmap() {
		return mBitmap;
	}

	public String getPath() {
		return mPath;
	}

	public void setName(String mName) {
		this.mName = mName;
	}

	public String getName() {
		if (mPath.contains("/")) {
			int lastCharInDirPath = mPath.lastIndexOf("/");
			String path = mPath.substring(0, lastCharInDirPath);
			String name = mPath.replace(path, "");
			return name;
		} else {
			return mName;
		}
	}

	public String getCleanName() {
		return getName().replace(".jpg", "");
	}

	public boolean isDimmed() {
		return isDimmed;
	}

	public void setDimmed(boolean isDimmed) {
		this.isDimmed = isDimmed;
	}
}
